module tt

let entries = seq {
 let lines = System.IO.File.ReadAllText(@"timetracker.csv").Split('\n')
 for l in lines do
  let s = l.Split(';')
  if (s.Length > 3) then
   let dt = s.[0].Split(' ');
   yield (dt.[0], dt.[1], System.Int32.Parse(s.[1]), s.[2], l.Substring(s.[0].Length + s.[1].Length + s.[2].Length + 3).Trim('"'))
}

let first (a, _, _, _, _) = a
let fourth (_, _, _, d, _) = d
let fifth (_, _, _, _, e) = e

let query f s x = entries
               |> Seq.groupBy f
               |> Seq.map (fun (key, values) -> (key, values |> Seq.sumBy (fun (_, _, v, _, _) -> if (v < x) then 1 else 0)))
               |> Seq.sortBy s
               |> Seq.map (fun (a, b) -> (a, b / 720, (b % 720) / 12))

let msnd = (fun x -> -snd(x))

let apps = query fourth msnd 30
let titles = query fifth msnd 30
let days = query first fst 30

